<template>
  <div>
    <div id="user_search">
      <div style="float:left">
      用户名：
      <el-input v-model="input" style="width: 80px; padding-right: 5px;"></el-input>
      邮箱：
      <el-input v-model="input" style="width: 80px; padding-right: 5px;"></el-input>
      手机：
      <el-input v-model="input" style="width: 80px; padding-right: 5px;"></el-input>
      </div>
      <el-button type="primary" icon="el-icon-search" @click="dialogFormVisible = true;" />
      <el-button type="primary" icon="el-icon-refresh" size="small" @click=";" />
    </div>

    <el-dialog title="新增用户" :visible.sync="dialogFormVisible">
        <el-form :model="form" :label-width="formLabelWidth" :label-position="labelPosition">
          <el-form-item label="用户名">
            <el-input v-model="form.name" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input type="password" v-model="form.password"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
        </div>
      </el-dialog>

    <el-table
      ref="multipleTable"
      row-class-name="row-class"
      :data="tableData3"
      tooltip-effect="dark"
      style="width: 100%;"
      border
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        label="日期"
        width="120">
        <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="120">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 20px">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="10"
        layout="prev, pager, next, jumper"
        :total="1000">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'users',
  data () {
    return {
      input: '',
      users: [],
      tableData3: [{
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }],
      dialogFormVisible: false,
      form: {
          name: '',
          password: ''
      },
      labelPosition: 'left',
      formLabelWidth: '80px',
      currentPage: 1,
      multipleSelection: []
    }
  },
  methods: {
    deleteUser: function () {
      this.users.pop()
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleCurrentChange() {
      console.log('CurrentPage: ' + this.currentPage)
    },
    handleEdit(index, row) {
      console.log('index: ' + index + ", " + row.address)
    },
    handleDelete(index, row) {

    },
  },
  created () {
    this.$axios.get('http://jsonplaceholder.typicode.com/users')
    .then((data) => {
      this.users = data.data
    })
    // this.$axios({
    //   methods: 'get',
    //   url: 'http://jsonplaceholder.typicode.com/users',
    //   data: {}
    // })
  },
}
</script>

<!-- scoped:域，CSS只在当前组件生效 -->
<style scoped>
.row-class {
  height: 10px;
}

#user_search {
  padding-left: 20px;
  background-color: lightgrey;
  height: 60px;
  color: rgba(17, 17, 17, 0.8);
  font-size: 14px;
  font-weight: bold;
  text-align: left;
  line-height: 60px;
}

.users {
  width: 100%;
  max-width: 1200px;
  margin: 40px auto;
  padding: 0 20px;
  box-sizing: border-box;
}

.el-table {
  text-align: left;
}
</style>